function getweather(city){
    $.ajax({
        type: 'GET',
        dataType: 'jsonp',
        async: false,
        url: 'http://api.asilu.com/weather/?callback=getname&city='+city,
        success:function(data){
          weather(data)
        }
    })
}    

function weather(data){
    console.log(data)
    $("#date-day")[0].innerHTML = data.date
    $("#date-dayname")[0].innerHTML = data.weather[0].date.slice(0,3)
    $("#pm")[0].innerHTML = data.pm25
    $("#humidity")[0].innerHTML = "暂无"
    $("#wind")[0].innerHTML = data.weather[0].wind
    $("#location")[0].innerHTML = data.city
    $("#weather-temp")[0].innerHTML = data.weather[0].temp.slice(0,3) + "℃";
    $("#weather-desc")[0].innerHTML = data.weather[0].weather
    $("#weather-1")[0].innerHTML = weatherIcon(data,1);

    var day1 = $("#day1")
    var span1 =$(day1).find('span') 
    var day2 = $("#day2")
    var span2 =$(day2).find('span') 
    var day3 = $("#day3")
    var span3 =$(day3).find('span') 
    var day4 = $("#day4")
    var span4 =$(day4).find('span')  
    
    span1[0].innerHTML = weatherIcon(data,1);
    span1[1].innerHTML = data.weather[0].date.slice(0,3);
    span1[2].innerHTML = data.weather[0].temp;
    
    span2[0].innerHTML = weatherIcon(data,2);
    span2[1].innerHTML = data.weather[1].date
    span2[2].innerHTML = data.weather[1].temp;

    span3[0].innerHTML = weatherIcon(data,3);
    span3[1].innerHTML = data.weather[2].date
    span3[2].innerHTML = data.weather[2].temp;

    span4[0].innerHTML = weatherIcon(data,4);
    span4[1].innerHTML = data.weather[3].date
    span4[2].innerHTML = data.weather[3].temp;

}
function weatherIcon(data,t) {

    if (data.weather[t - 1].icon1.search("yin") != -1) {
        return "&#xe608;";
    }
    if(data.weather[t - 1].icon1.search("duoyun") != -1){
            return "&#xe607;";
        }
    if(data.weather[t - 1].icon1.search("qing") != -1){
            return "&#xe600;";
    }
    if(data.weather[t - 1].icon1.search("xiaoyu") != -1){
            return "&#xe626;";
    }
    if(data.weather[t - 1].icon1.search("zhongyu") != -1){
            return "&#xe667;";
    }
    if(data.weather[t - 1].icon1.search("dayu") != -1 || data.weather[0].icon1.search("baoyu") != -1){
            return "&#xe610;";
    }
    if(data.weather[t - 1].icon1.search("zhenyu") != -1){
            return "&#xe701;";
    }    
}

$("#location-button").click(function(){
    var city=$("#city").val()
    getweather(city)
})

window.onload = function() {
    this.getweather('北京')
}